package assets.unloading;

import java.util.HashMap;
import java.util.Map;

import assets.Asset;

import util.collections.CacheReaper;

/**
 * Reaps a cache containing assets.
 * 
 * @author Joel Rausch
 */
public class AssetCacheReaper extends CacheReaper {

	/** Map of tracked assets. */
	private final Map<String, AssetUnloader> tracked =
			new HashMap<String, AssetUnloader>();
	
	@Override
	public void track(String key, Object value) {
		Asset asset = (Asset) value;
		AssetUnloader unloader = asset.unloader();
		if(unloader != null) {
			tracked.put(key, unloader);
		}
	}

	@Override
	public void reap(String key) {
		AssetUnloader unloader = tracked.remove(key);
		if(unloader != null) {
			unloader.unload();
		}
	}
}
